﻿using System;
using System.Reflection;

namespace Dsl.Ped.Common.Helpers
{
    /// <summary>
    /// Helper of the <see cref="Uri"/>
    /// </summary>
    public class UriHelper
    {
        /// <summary>
        /// Get the <see cref="Uri"/> of a resource of an application (<see cref="Assembly"/>)
        /// </summary>
        /// <param name="assemblyName">Name of the <see cref="Assembly"/> which resource we are looking for</param>
        /// <param name="resourceRelativePath">Relative path to the resource in the <see cref="assemblyName"/> <see cref="Assembly"/></param>
        /// <returns><see cref="Uri"/> of the resource</returns>
        public static Uri GetApplicationResource(string assemblyName, string resourceRelativePath)
        {
            string uri = String.Format("pack://application:,,,/{0};component/{1}", assemblyName, resourceRelativePath);
            return new Uri(uri, UriKind.Absolute);
        }

        /// <summary>
        /// Get the <see cref="Uri"/> of a resource in the <see cref="Assembly"/>
        /// </summary>
        /// <param name="assembly"><see cref="Assembly"/> where there is a resource located</param>
        /// <param name="resourceRelativePath">Relative path to the resource in the <see cref="assembly"/> <see cref="Assembly"/></param>
        /// <returns><see cref="Uri"/> of the resource in the <see cref="assembly"/></returns>
        public static Uri GetAssemblyResource(Assembly assembly, string resourceRelativePath)
        {
            var fullName = assembly.FullName.Split(new char[] { ',' })[0];
            string uri = String.Format("pack://application:,,,/{0};component/{1}", fullName, resourceRelativePath);
            return new Uri(uri, UriKind.Absolute);
        }
    }
}
